<?php
class TicketCatesController extends AppController {
	
	/**
	 * 票品分类列表
	 * @author mingxing.zhao@qq.com
	 * @Date 2013-12-29
	 * @param
	 * @return
	 */
	public function admin_index() {
		$url = array('admin'=>true,'controller'=>'TicketCates','action'=>'jsonPage');
		$param = $this->TicketCate->pageParam($url);
		$this->set('paginationScript',$this->TicketCate->showTreePagination($param));
	}
	
	/**
	 *
	 * 用户查询数据
	 * @author mingxing.zhao@qq.com
	 * @Date 2013-12-29
	 * @param
	 * @return
	 */
	function admin_jsonPage(){
		$this->autoRender = false;
	
		$return = array(
			'page'=>0,			 
			'total'=>0,			 
			'records'=>0,		 
			'rows'=>array()		 
		);
		$parentId = empty($_POST['nodeid'])?1:$_POST['nodeid'];
		$level = empty($_POST['n_level'])?0:$_POST['n_level'];
		$rows = $this->TicketCate->ajaxTreeCategory($parentId,$level+1);
		$return['rows'] =$rows;
		
		echo json_encode($return);
	}
	/**
	 * 添加票品分类
	 * @author mingxing.zhao@qq.com
	 * @Date 2013-12-29
	 * @param
	 * @return
	 */
	function admin_add($parent_id = 1) {
		if ($this->request->is('post')) {
			$this->TicketCate->create();
			if ($this->TicketCate->save($this->data)) {
				$this->Session->setFlash(__('添加成功'),'tip/tip_float',array('t'=>'success'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('添加失败'),'tip/tip_float',array('t'=>'error'));
			}
		}
		$this->set('articleCates',$this->TicketCate->ArticleCate->getSiteEnable($this->Session->read('SITEID')));
		$this->set('parent_id',$parent_id);
	}
	/**
	 * 修改票品分类
	 * @author mingxing.zhao@qq.com
	 * @Date 2013-12-29
	 * @param
	 * @return
	 */
	function admin_edit($id = null) {
		$this->TicketCate->id = $id;
		if (!$this->TicketCate->exists()) {
			throw new NotFoundException(__('Invalid sys area'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			if ($this->TicketCate->save($this->request->data)) {
				$this->Session->setFlash(__('操作成功！'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('操作失败！'));
			}
		} else {
			$this->request->data = $this->TicketCate->read(null, $id);
		}
		$this->set('articleCates',$this->TicketCate->ArticleCate->getSiteEnable($this->request->data['TicketCate']['sys_website_id']));
	}
	
	function admin_option($parent_id){
		$this->set('state',true);
		$data = $this->TicketCate->findTicketCateList($parent_id);
		$this->set('data',$data);
	}
	
	/**
	 * 通过上级id取得下级票品分类
	 * @author zmx@gootop.net  
	 * @Date 2012-12-4
	 * @param
	 * @return 
	 */
	function getAreaByPid($parent_id = 139){
		return $this->findAreaList($parent_id);
	}
}
